﻿let sensorListAll=[];
$(function () {
	// if(!notLogin())
	// 	return;
	//设备运行情况 左边第一个
	setInterval(setChart_1, 3000);
	//中间CAD
	setCenterCAD();
	//饼状气体分布
	setChartPieNew();
	//滚动安全监控数据
	scrollAnQuan();
	//滚动实时数据
	scrollTable();
	//矿名称
	setMineName();
	//最近30天统计
	set_chart_sensorDataByDay();
	//无超限天数
	set_notOverrunDay();
	//矿维护人员
	setMinePerson();
	//右上角实时时间
	setInterval(setDateInfo, 1000);
	//刷新切换 无超限和系统运行天数
	setInterval(setChangeOverrundayAndSyRunday, 5000);

	//特效安全监控系统对比
	setInterval(comparisonData, 5000);
});

var bigMapServer= {
	getOverRunDeviceList: function (){
         return overrunSensorList;
    },
}

function runInfo(typeInfo) {
	showDeviceStatus(typeInfo);
}

function showDeviceStatus(type) {
	if(type==0||type==undefined)
		return ;
	let titleStr="设备状态";
	if(type==1)
		titleStr="全部地点";
	if(type==2)
		titleStr="正常地点";
	if(type==3)
		titleStr="故障地点";
	if(type==4)
		titleStr="超限地点";
	let url="./examples/deviceStatus.html?type="+type;  //"http://localhost:9001/map_warningList.html";
	layer.open({
		moveOut:true,
		move:'.layui-layer-title',
		skin:'layui-layer-lan', // skin: 'layui-layer-demo', //样式类名
		type: 2
		,title: titleStr //不显示标题栏
		,closeBtn: 1
		,maxmin:true
		,fixed:false
		,area: ['850px','430px']
		,shade: 0.2
		,id: 'LAY_layuipro' //设定一个id，防止重复弹出
		//,btn: '关闭全部'
		,btnAlign: 'c'
		,move:true
		//,moveType: 0 //拖拽模式，0或者1
		,resize:true
		,anim:1 //弹出动画
		,content:url //'<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">你知道吗？亲！<br>layer ≠ layui<br><br>layer只是作为Layui的一个弹层模块，由于其用户基数较大，所以常常会有人以为layui是layerui<br><br>layer虽然已被 Layui 收编为内置的弹层模块，但仍然会作为一个独立组件全力维护、升级。<br><br>我们此后的征途是星辰大海 ^_^</div>'
	});
}

//未登陆回登陆页
function notLogin() {
	let loginUser=JSON.parse(localStorage.getItem("robotUser"));
	if(loginUser==null||loginUser==undefined)
	{
		alert("未登陆。。");

		let postData = {"appkey": "data_home_url"};
		let settingsInfo = sensorServer.getSettingsByAppKey(postData);
		if (settingsInfo != undefined && settingsInfo != null) {
			if (settingsInfo.appval != undefined && settingsInfo.appval != null) {
				console.log(settingsInfo.appval);
				if (settingsInfo.appval == "")
					return;
				window.open(settingsInfo.appval);
			}else{
				$("body").html("请返回登录页，登录后从新进入！");
			}
		}
		return false;
	}
	let username=loginUser.username;
	return  true;
}

function  click_mine_name(type) {
	showDeviceStatus(type);
	return;
	$('.filterbg').show();
	$('.popup').show();
	$('.popup').width('3px');
	$('.popup').animate({height: '76%'},400,function(){
		$('.popup').animate({width: '82%'},400);
	});
}

function showDeviceStatus(type) {
    if(type==0||type==undefined)
    	return ;
	let titleStr="设备状态";
	if(type==3)
		titleStr="故障地点";
	if(type==4)
		titleStr="超限地点";
	let url="./examples/deviceStatus.html?type="+type;  //"http://localhost:9001/map_warningList.html";
	layer.open({
		moveOut:true,
		move:'.layui-layer-title',
		skin:'layui-layer-lan', // skin: 'layui-layer-demo', //样式类名
		type: 2
		,title: titleStr //不显示标题栏
		,closeBtn: 1
		,maxmin:true
		,fixed:false
		,area: ['850px','430px']
		,shade: 0.2
		,id: 'LAY_layuipro' //设定一个id，防止重复弹出
		//,btn: '关闭全部'
		,btnAlign: 'c'
		,move:true
		//,moveType: 0 //拖拽模式，0或者1
		,resize:true
		,anim:1 //弹出动画
		,content:url //'<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">你知道吗？亲！<br>layer ≠ layui<br><br>layer只是作为Layui的一个弹层模块，由于其用户基数较大，所以常常会有人以为layui是layerui<br><br>layer虽然已被 Layui 收编为内置的弹层模块，但仍然会作为一个独立组件全力维护、升级。<br><br>我们此后的征途是星辰大海 ^_^</div>'
	});
}

function popupCloseClick() {
	$('.filterbg').hide();
	$('.popup').hide();
}

function setChart_1() {
	let postData = {"page": 1, "rows": 1000};
	let resultData = sensorServer.getSensorList(postData);
	if(resultData==undefined||resultData==null)
		return;
	let total = resultData.total;
	let sensorList = resultData.data;

	let dataList = [];
	let normal = new dataListElme();
	normal.name = "正常";
	normal.value = 1;

	let errDevice = new dataListElme();
	errDevice.name = "故障";
	errDevice.value = 0;

	let normalCount = 0;
	let errCount = 0;
	let overrunCount = 0;
	for (let i = 0; i < sensorList.length; i++) {
		let elme = sensorList[i];
		elme.deviceConnect =true; //永不故障测试
		elme.ledConnect=1;//永不故障测试
		if (elme.deviceConnect == false || elme.deviceConnect == 0 || elme.ledConnect == false || elme.ledConnect == 0) {
			errCount++;
			continue;
		}
		normalCount++;
	}
	normal.value = normalCount;
	errDevice.value = errCount;

	// $("#demo1_h").html("正常设备"+normalCount);
	// $("#demo2_h").html("故障设备"+errCount);
	// $("#demo3_h").html("超限设备"+overrunCount);
	overrunCount=overrunSensorCount;// 从定时器里获取的。
	localStorage.setItem("overrunDeviceList",JSON.stringify(overrunSensorList));
	$("#jinri_by1").html("正常设备" + normalCount); //normalCount 26
	$("#jinri_zy1").html("故障设备" + errCount); //errCount   0
	$("#jinri_lg1").html("超限设备" + overrunCount); //overrunCount  0

	dataList.push(normal);
	dataList.push(errDevice);
	//	setPieData(dataList);

	let normalPre = ((normalCount / sensorList.length) * 100).toFixed(2) + "%";
	if (normalCount == 0) {
		normalPre = "0%";
	}

	let errorPre = ((errCount / sensorList.length) * 100).toFixed(2) + "%";
	//debugger;
	if (errCount == 0) {
		errorPre = "0%";
	}


	let overrunCountPre = ((overrunCount / sensorList.length) * 100).toFixed(2) + "%";
	if (overrunCount == 0) {
		overrunCountPre = "0%";
	}
	// //全部默认正常 (演示后注释掉)
	normalPre=203;// normalPre='100%';
	$("#all_by2").html(normalPre); // errorPre = "0%";
	$("#normal_by2").html(normalPre);

	$("#jinri_by2").css("width", normalPre);
	$("#jinri_zy2").css("width", errorPre);
	$("#jinri_lg2").css("width", overrunCountPre);

	$("#jinri_by3").html(normalPre);
	$("#jinri_zy3").html(errorPre);
	$("#jinri_lg3").html(overrunCountPre);


	$("#all_by1").html("全部"+sensorList.length+"套");
	$("#all_zy2").css("width", "100%");
	$("#all_lg3").html("100%");
	// layui.use('element', function() {
	// 	var $ = layui.jquery
	// 			, element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
	// 	element.progress('demo1',normalPre);
	// 	element.progress('demo2',errorPre);
	// 	element.progress('demo3',overrunCount);
	// });
	sensorListAll=sensorList;
	refShowTable(sensorList);
}
function showRunDevice(type){
     if(type==3){
		 let fileFilterList=[];
		 for (let i=0;i<sensorListAll.length;i++){
			 if(sensorListAll[i].deviceConnect==false||sensorListAll[i].deviceConnect==0 ||
				sensorListAll[i].ledConnect==false||sensorListAll[i].ledConnect==0){
				 fileFilterList.push(sensorListAll[i]);
			 }
		 }
		 refShowTable(fileFilterList,"#demo");
		 click_mine_name(type);
	 }
     if(type==4){
		 let fileFilterList=[];
		 for (let i=0;i<overrunSensorList.length;i++){
			 fileFilterList.push(overrunSensorList[i]);
		 }
		 refShowTable(fileFilterList,"#dem4");
		 click_mine_name(type);
	 }
}

function refShowTable(dataSensor,dataTableId){
	let toolbarInfo='';
	layui.use('table', function () {
		var table = layui.table;
		//第一个实例
		table.render({
			elem:dataTableId // '#demo'
			//,height: 500
			, data: dataSensor
			,page: false //开启分页
			,limit: 100

			,toolbar: toolbarInfo//'#toolbarMenu',
			,cols: [[ //表头
				// {field:"pid", checkbox:true,fixed: 'left'},
				{field: 'pid', title: '编号',width:80,sort: true, fixed: 'left'} //, fixed: 'left'
				, {field: 'devicelocation', title: '安装位置',width:150}//,width:150
				, {field: 'deviceid', title: '设备唯一标识',width:150}//,width:150
				, {field: 'deviceip', title: '传感器IP',width:150}//,width:150
				, {field: 'deviceConnect', title: '传感器数据',width:100
					,templet: function (d) {
					    let msg1="链接";
						let msg2="中断";
						return d.deviceConnect == "1" ? "<i class='layui-icon' style='color:green;margin-right:5px'>&#xe617;</i>" + msg1:
							   "<i class='layui-icon' style='color:red;margin-right:5px'>&#xe617;</i>" +msg2;
					}
				}
				, {field: 'ledDeviceIP', title: 'LED大屏'}
				, {field: 'ledConnect', title: 'LED链接'
					,templet: function (d) {
						let msg1="链接";
						let msg2="中断";
						return d.ledConnect == true ? "<i class='layui-icon' style='color:green;margin-right:5px'>&#xe617;</i>" + msg1:
							"<i class='layui-icon' style='color:red;margin-right:5px'>&#xe617;</i>" +msg2;
					}
				}
				, {field: 'lastDataTime', title: '最后上数时间'}
			]]
			,loading:true,
			done:function (res, curr, count) {
				$('th').css({
					'background-color': '#061f3e', 'color': '#fff','font-weight':'bold'
				});
				$('th').css({
					'background-color': '#061f3e', 'color': '#fff','font-weight':'bold'
				});
				$('tr').css({
					'background-color': '#061f3e', 'color': '#fff','font-weight':'bold'
				});
				$("[data-field='smokenormal']").children().each(function(){
					// if($(this).text()!=''){
					//     $(this).text("正常")
					// }
					if($(this).text()==0){
						$(this).text("正常")
					}else if($(this).text()==1){
						$(this).text("烟")
					}else if($(this).text()==""){
						$(this).text("")
					}
				});
				$("[data-field='opendefault']").children().each(function(){
					if($(this).text()==1){
						$(this).text("手动")
					}else if($(this).text()==0){
						$(this).text("自动")
					}
				});
				$("[data-field='ch4']").children().each(function(){
					if($(this).text()==0||$(this).text()=="0"){
						$(this).text("0.00")
					}
				});
				$("[data-field='co2']").children().each(function(){
					if($(this).text()==0||$(this).text()=="0"){
						$(this).text("0.00")
					}
				});
				$("[data-field='luxurydevice']").children().each(function(){
					if($(this).text()==1){
						$(this).text("豪华版")
					}else if($(this).text()==0){
						$(this).text("普通版")
					}
				});

				// $("[data-field='deviceConnect']").children().each(function(){
				// 	if($(this).text()=='true'){
				// 		$(this).text("通讯正常");
				// 		$(this)[0].style.color="green";
				// 	}else if($(this).text()=='false'){
				// 		$(this).text("设备断开");
				// 		$(this)[0].style.color="red";
				// 	}
				// });
				//
				// $("[data-field='ledConnect']").children().each(function(){
				// 	if ($(this).text() != 'LED链接')  {
				// 		if ($(this).text() == '1') {
				// 			$(this).text("通讯正常");
				// 			$(this)[0].style.color="green";
				// 		} else {
				// 			$(this).text("设备断开");
				// 			$(this)[0].style.color="red";
				// 		}
				// 	}
				// });
			}
		});

		//监听单元格编辑
		table.on('edit(test_table)',
			function (obj) {
				//如果不是管理员
				if(!sensorServer.getRoleIsAdmin()){
					alert("操作员无权限修改");
					var oldText = $(this).prev().text();
					$(this).val(oldText);
					return;
				}
				var value = obj.value //得到修改后的值
					,
					data = obj.data //得到所在行所有键值
					,
					field = obj.field; //得到字段
				layer.msg('[ID: ' + data.pid + '] ' + field + ' 字段更改为：' + value);
				//updateTable(data.pid,value);
				obj.data.robotpid=1;
				var jsonResult = sensorServer.updateSensorInfo1(obj.data);
				console.log(jsonResult);
			});

		//监听行单击事件（双击事件为：rowDouble）
		//table.on('row(test_table)', function(obj){
		// var data = obj.data;
		// layer.alert(JSON.stringify(data), {
		//     title: '当前行数据：'
		// });

		//标注选中样式
		//obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
		//  });

		//头工具栏事件
		table.on('toolbar(test_table)', function(obj) {
			var checkStatus = table.checkStatus(obj.config.pid);
			switch (obj.event) {
				case 'delete':
					layer.msg('data:'+obj.data.pid);
					del(obj);
					break;
				case 'delCheckData':
					// var data = checkStatus.data;
					// layer.alert(JSON.stringify(data));
					// break;
					layer.confirm('确认要删除吗？',function(index){
						for(let i=0;i<obj.config.data.length;i++)
						{
							if(obj.config.data[i].LAY_CHECKED){
								sensorServer.delSensorInfo(obj.config.data[i]);
								layer.msg('已删除!',{icon:1,time:1000});
							}
						}
						location.reload();
					});
					break;
			};
		});
		//列里的工具栏
		table.on('tool(test_table)',
			function(obj) {
				//如果不是管理员
				if(!sensorServer.getRoleIsAdmin()){
					alert("操作员无权限修改");
					return;
				}
				//var checkStatus = table.checkStatus(obj.config.pid);
				switch (obj.event) {
					case 'delete':
						layer.msg('data:'+obj.data.pid);
						del(obj);
						break;
					case 'openDefault':
						layer.msg('data:'+obj.data.pid);
						openDefaultClick(obj);
						break;
					case 'changeDeviceType':
						layer.msg('data:'+obj.data.pid);
						changeDeviceType(obj);
						break;
				};
			});
	});
}

//安全监控系统对比
let startSplitIndex=0;
//js截取 指定位数。不够从0 开始

function startSplitAll(startIndex,endIndex,sensorList) {
    let newDataList=[];
    //接收的范围在里面 直接截取
	if(startIndex==0) {
		if (startIndex + endIndex < sensorList.length - 1) {
			newDataList = sensorList.slice(startIndex, startIndex + endIndex);
			startSplitIndex = endIndex;
		}
	}else{
		newDataList = sensorList.slice(startIndex,endIndex);
		startSplitIndex = endIndex;
	}
	console.log("startSplitIndex:\t"+startSplitIndex);
	return newDataList;
}
let randNum=0;
function  comparisonData() {
	let postData = {"page": 1, "rows": 1000};
	let resultData = sensorServer.getSensorList(postData);
	if(resultData==null||resultData==undefined)
		return;
	let total = resultData.total;
	if(total==0)
		return;
	let liList='';
	let sensorList = resultData.data;

	let splitLength=getrand(6, 6);
	let endIndex=startSplitIndex+splitLength;
	let sensorListNew=startSplitAll(startSplitIndex,endIndex,sensorList);

	if(sensorListNew.length<splitLength){  //最后循环到最后，如果去不够取，从头取几条放进去。
		let chaNum=(splitLength-sensorListNew.length);
		let  listTmp=sensorList.slice(0,chaNum);
		for (let i=0;i<listTmp.length;i++){
			sensorListNew.push(listTmp[i]);
		}
		startSplitIndex=0;
	}

	sensorList=sensorListNew;
	let arrBorderColorClass=["border-yellow","border-green","border-blue","border-red"];
	let arrFontColorClass=["color-yellow","color-green","color-blue","color-red"];
	let addGas=["甲烷","二氧化碳","一氧化碳","温度","氧气"];
	//for (let i = 0; i < sensorList.length; i++) {
	for (let i = 0; i < 5; i++) {
		let address=addGas[i];
		if(address.length>6){
			address=address.substr(0,6);
		}
		let colorIndexRand = getrand(0, arrBorderColorClass.length - 1);
		let colorStr = arrBorderColorClass[colorIndexRand];
		let fontColor=arrFontColorClass[colorIndexRand];

		let liStr='<li onclick="safetyMonitoring(this)" class="'+fontColor+'">' +
			'<span class="'+colorStr+'" id="indicator1" total="0.01">##totalValue##</span>' +
			'<p>##devicelocation##</p>' +
			'</li>';
		let value=randomNum(0.01,0.03,2);
		if(randNum%2==0){
			value=randomNum(1,2,0);
		}
		liStr=liStr.replace(/##totalValue##/g,value.toString()).replace(/##devicelocation##/g,address);
		liList+=liStr;

	}
	randNum++;
	$("#ul_comparison").html('');
	$("#ul_comparison").find("li").remove();
	$("#ul_comparison").append(liList);
}


function setCenterCAD() {
	//src="http://localhost:63342/map/three.js-master/examples/index_bigmap_center.html?_ijt=qo8688p9tsb6vp0k3bsimvmv7u"
	//$("#iframe_map").attr("src","./examples/index_bigmap_center.html");
	//document.getElementById("center").innerHTML = '<object type="text/html" data="examples/index_bigmap_center_1.html" width="100%" height="100%"></object>';
	document.getElementById("center").innerHTML = '<object type="text/html" data="./baidumap.html" width="100%" height="100%"></object>';
}

//无超限天数
function set_notOverrunDay() {
	let postData = {"page": 1, "rows": 1000};
	let resultData = sensorServer.getSensorList(postData);
	if(resultData==undefined||resultData==null)
		return;
	let total = resultData.total;
	let sensorList = resultData.data;
	for (let i = 0; i < sensorList.length; i++) {
		set_notOverrunDayAddress(sensorList[i].devicelocation);
	}
}

//无超限
function set_notOverrunDayAddress(address) {
	let postData = {"appkey": "not_overrun_Day"};
	let settingsInfo = sensorServer.getSettingsByAppKey(postData);
	if (settingsInfo != undefined && settingsInfo != null) {
		if (settingsInfo.appval != undefined && settingsInfo.appval != null) {
			console.log(settingsInfo.appval);
			if (settingsInfo.appval == "")
				return;
			let day = "0";
			//矿上的无超限天数
			day = GetNumberOfDays(settingsInfo.appval, new Date());
			//矿上的无超限天数
			let mineOverrunday = "<span style='font-size: 36px;'>&nbsp;&nbsp;" + day + "</span>" + "+";
			//自己的无超限天数
			let systemOverrunday = "<span style='font-size: 40px;'>" + 30 + "</span>";
			$("#miri_ditie").html(mineOverrunday + systemOverrunday);
		}
	}
	//
	//$("#miri_ditie_address").html(address+": ");
}

let runday = true;

//设置右上角无超限天数和 系统运行天数
function setChangeOverrundayAndSyRunday() {
	runday = true;
	if (runday) {
		$("#right_title").html("系统运行天数-小保当二号井");
		systemRunInfo();
		runday = false;
	} else {
		$("#right_title").html("无超限天数");
		set_notOverrunDayAddress("");
		runday = true;
	}
}

//系统运行天数
function systemRunInfo() {
	let day="1";
	let postData = {"appkey": "system_install_time"};
	let settingsInfo = sensorServer.getSettingsByAppKey(postData);
	if (settingsInfo != undefined && settingsInfo != null) {
		if (settingsInfo.appval != undefined && settingsInfo.appval != null) {
			console.log(settingsInfo.appval);
			if (settingsInfo.appval == "")
				return;
			day = GetNumberOfDays(settingsInfo.appval, new Date());
		}
	}
	//day=56;
	if(day==0){
		day=1; //最少一天
	}
	let syDay = "<span style='color: orange; font-size: 36px;'>&nbsp;&nbsp;&nbsp;&nbsp;" + day + "</span>";
	$("#miri_ditie").html(syDay); //
}

//设置实时数据滚动显示
function scrollTable() {
	$('.tbl-body tbody').empty();
	$('.tbl-header tbody').empty();
	var str = '';
	var Items = ''; /*[{"Ranking":"1","City":"保定","SaleIncome":"2506734.43","SaleRough":"296071.96","SalePlan":"7200000","PlanFinish":"34.82","TonOilincome":"264.15","OilTransform":"29.62","An":"53.00","Mom":"-13.00"},
		{"Ranking":"2","City":"沧州","SaleIncome":"1425935.58","SaleRough":"93717.83","SalePlan":"3200000","PlanFinish":"44.56","TonOilincome":"366.59","OilTransform":"11.23","An":"65.00","Mom":"43.00"},
		{"Ranking":"3","City":"秦皇岛","SaleIncome":"1372207.38","SaleRough":"241071.82","SalePlan":"3000000","PlanFinish":"45.74","TonOilincome":"342.32","OilTransform":"6.61","An":"34.00","Mom":"7.00"},
		{"Ranking":"4","City":"衡水","SaleIncome":"972451.15","SaleRough":"87638.60","SalePlan":"2700000","PlanFinish":"36.02","TonOilincome":"246.03","OilTransform":"11.56","An":"15.00","Mom":"-18.00"},
		{"Ranking":"5","City":"石家庄","SaleIncome":"939010.52","SaleRough":"140217.37","SalePlan":"7200000","PlanFinish":"13.04","TonOilincome":"139.44","OilTransform":"19.23","An":"-57.00","Mom":"-48.00"},
		{"Ranking":"6","City":"邢台","SaleIncome":"774274.70","SaleRough":"124693.90","SalePlan":"3700000","PlanFinish":"20.93","TonOilincome":"138.87","OilTransform":"9.44","An":"-20.00","Mom":"-44.00"},
		{"Ranking":"7","City":"唐山","SaleIncome":"680456.79","SaleRough":"50542.14","SalePlan":"3600000","PlanFinish":"18.90","TonOilincome":"243.60","OilTransform":"16.95","An":"-29.00","Mom":"-49.00"},
		{"Ranking":"8","City":"张家口","SaleIncome":"613319.87","SaleRough":"176075.96","SalePlan":"3000000","PlanFinish":"20.44","TonOilincome":"87.09","OilTransform":"7.97","An":"2.00","Mom":"-24.00"},
		{"Ranking":"9","City":"中油华奥","SaleIncome":"596575.25","SaleRough":"387024.26","SalePlan":"11000000","PlanFinish":"5.42","TonOilincome":"93.58","OilTransform":"19.06","An":"35.00","Mom":"6.00"},
		{"Ranking":"10","City":"承德","SaleIncome":"589048.12","SaleRough":"68966.73","SalePlan":"2200000","PlanFinish":"26.77","TonOilincome":"193.24","OilTransform":"11.29","An":"30.00","Mom":"-28.00"},
		{"Ranking":"11","City":"廊坊","SaleIncome":"515448.14","SaleRough":"137934.72","SalePlan":"3500000","PlanFinish":"14.73","TonOilincome":"95.47","OilTransform":"8.80","An":"-48.00","Mom":"-3.00"},
		{"Ranking":"12","City":"瑞州","SaleIncome":"399875.26","SaleRough":"85371.46","SalePlan":"2000000","PlanFinish":"19.99","TonOilincome":"114.42","OilTransform":"11.42","An":"128.00","Mom":"-30.00"},
		{"Ranking":"13","City":"石家庄中油","SaleIncome":"90543.62","SaleRough":"20065.14","SalePlan":"430000","PlanFinish":"21.06","TonOilincome":"213.44","OilTransform":"20.45","An":"-24.00","Mom":"-17.00"},
		{"Ranking":"14","City":"辛集中油","SaleIncome":"49255.52","SaleRough":"8743.12","SalePlan":"250000","PlanFinish":"19.70","TonOilincome":"202.67","OilTransform":"29.95","An":"19.00","Mom":"-6.00"}]
    */

	let postData = {"page": 1, "rows": 1000};
	let resultData = sensorServer.getSensorList(postData);
	if(resultData==undefined||resultData==null)
		return;
	let total = resultData.total;
	let sensorList = resultData.data;
	Items = sensorList;
	$.each(Items, function (i, item) {
		str = '<tr>' +
			'<td>' + item.pid + '</td>' +
			'<td>' + item.devicelocation + '</td>' +
			'<td>' + item.ch4 + '</td>' +
			'<td>' + (+item.co2).toFixed(1) + '</td>' +
			'<td>' + (+item.co) + '</td>' +
			'<td>' + (+item.temperature).toFixed(1) + '</td>' +
			'<td>' + (item.humidity).toFixed(1) + '</td>' +
			'<td>' + (+item.o2).toFixed(1) + '</td>' +
			'</tr>'

		$('.tbl-body tbody').append(str);
		$('.tbl-header tbody').append(str);
	});
	if (Items.length > 0) {
		$('.tbl-body tbody').html($('.tbl-body tbody').html() + $('.tbl-body tbody').html());
		$('.tbl-body').css('top', '0');
		var tblTop = 0;
		var speedhq = 50; // 数值越大越慢
		var outerHeight = $('.tbl-body tbody').find("tr").outerHeight();

		function Marqueehq() {
			if (tblTop <= -outerHeight * Items.length) {
				tblTop = 0;
			} else {
				tblTop -= 1;
			}
			$('.tbl-body').css('top', tblTop + 'px');
		}

		MyMarhq = setInterval(Marqueehq, speedhq);

		// 鼠标移上去取消事件
		$(".tbl-header tbody").hover(function () {
			clearInterval(MyMarhq);
		}, function () {
			clearInterval(MyMarhq);
			MyMarhq = setInterval(Marqueehq, speedhq);
		})
	}
}
//-----------------------------------------滚动安全监控数据-----------------------------------
function scrollAnQuan() {
	$('.tbl-body2 tbody').empty();
	$('.tbl-header2 tbody').empty();
	var str = '';
	var Items = '';
	let postData = {"page": 1, "rows": 1000};
	let resultData = sensorServer.getSensorList(postData);
	if(resultData==undefined||resultData==null)
		return;
	let total = resultData.total;
	let sensorList = resultData.data;
	Items = sensorList;
	$.each(Items, function (i, item) {
		str = '<tr>' +
			'<td>' + item.pid + '</td>' +
			'<td>' + item.devicelocation + '</td>' +
			'<td>' + item.ch4 + '</td>' +
			'<td>' + (+item.co2).toFixed(1) + '</td>' +
			'<td>' + (+item.co) + '</td>' +
			'<td>' + (+item.temperature).toFixed(1) + '</td>' +
			'<td>' + (item.humidity).toFixed(1) + '</td>' +
			'<td>' + (+item.o2).toFixed(1) + '</td>' +
			'</tr>'

		$('.tbl-body2 tbody').append(str);
		$('.tbl-header2 tbody').append(str);
	});
	if (Items.length > 0) {
		$('.tbl-body2 tbody').html($('.tbl-body2 tbody').html() + $('.tbl-body2 tbody').html());
		$('.tbl-body2').css('top', '0');
		var tblTop = 0;
		var speedhq = 50; // 数值越大越慢
		var outerHeight = $('.tbl-body2 tbody').find("tr").outerHeight();

		function Marqueehq2() {
			//console.log("挪动一点。。。");
			if (tblTop <= -outerHeight * Items.length) {
				tblTop = 0;
			} else {
				tblTop -= 1;
			}
			$('.tbl-body2').css('top', tblTop + 'px');
		}

		let MyMarhq = setInterval(Marqueehq2, speedhq);

		// 鼠标移上去取消事件
		$(".tbl-header2 tbody").hover(function () {
			clearInterval(MyMarhq);
		}, function () {
			clearInterval(MyMarhq);
			MyMarhq = setInterval(Marqueehq2, speedhq);
		})
	}
}

//-----------------------------------------滚动安全监控数据-----------------------------------


//展示报警数据
setInterval(showWarningInfo,10000);
var overrunSensorCount=0;
var overrunSensorList=[];
function showWarningInfo(){
	overrunSensorList=[];
	//获取最大报警上限值
	let postData={"page":1,"rows":1000};
	let maxGasValList=sensorServer.getMaxSetting(postData);

	let maxValInfo=null;
	if(maxGasValList.data.length>0){
		maxValInfo=maxGasValList.data[0];
	}
	if(maxValInfo==null)
		return;
	let resultData=sensorServer.getSensorList(postData);
	let total=resultData.total;
	let sensorList=resultData.data;
	sensorListAll=sensorList;
	let warningText="";
	overrunSensorCount=0;
	for (let i=0;i<sensorList.length;i++){
		let isOverrun=false;
		let sensorInfo=sensorList[i];
		if(sensorInfo.ch4>maxValInfo.ch4){
			warningText+="甲烷超限！CH4："+sensorInfo.ch4;
			isOverrun=true;
		}
		if(sensorInfo.co>maxValInfo.co){
			warningText+="一氧化碳超限！CO："+sensorInfo.co;
			isOverrun=true;
		}
		if(sensorInfo.co2>maxValInfo.co2){
			warningText+="二氧化碳超限！CO2："+sensorInfo.co2;
			isOverrun=true;
		}
		if(sensorInfo.temperature>maxValInfo.temperature){
			warningText+="温度超限！温度："+sensorInfo.temperature;
			isOverrun=true;
		}
		if(sensorInfo.o2<maxValInfo.o2){
			if(sensorInfo.o2>0) {  //不等于0
				warningText += "氧气超限！氧气：" + sensorInfo.o2;
				isOverrun=true;
			}
		}
		if(isOverrun) {
			overrunSensorCount++;
			overrunSensorList.push(sensorInfo);
		}
	}
	// if(warningText!=""){
	// 	$("#showWarningInfo").show();
	// 	$("#showWarningInfo")[0].innerText=warningText;
	// }else{
	// 	$("#showWarningInfo").hide();
	// }
	//
	//
	// //随时更新超限设备数量
	// let overrunCountPre=(overrunSensorCount/sensorList.length)*100+"%";
	// $("#demo3_h").html("超限设备"+overrunSensorCount);
	// if(overrunCountPre==0){
	// 	overrunCountPre="0%";
	// }
	//
	// layui.use('element', function() {
	// 	var $ = layui.jquery
	// 		, element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
	// 	element.progress('demo3',overrunCountPre);
	// });
}


//标题双击事件
let fullScreenStatus = false;

function titleClick() {
	let bd = document.documentElement;
	if (!fullScreenStatus) {
		fullScreenStatus = true;
		fullScreen(bd);
	} else {
		fullScreenStatus = false;
		exitFullScreen(bd);
	}
}

let centerFullScreenStatus = false;

function centerClick() {
	let bd = document.getElementById("center");
	if (!centerFullScreenStatus) {
		centerFullScreenStatus = true;
		fullScreen(bd);
	} else {
		centerFullScreenStatus = false;
		exitFullScreen(bd);
	}
}

//设置维护人员都有谁
function setMinePerson() {
	// let resultDataInfo = sensorServer.getMaintainPersonList({});
	let resultDataInfo = sensorServer.getMinesList({});
	// let colorArr = ["#e5f239", "#686dd4", "#1caa17", "#b5e713",
	// 	"#32ff20", "#3c8cd2", "#bd8ed2", "#ea61cc"];
	let colorArr = ["#32ff20","#32ff20"];

    if(resultDataInfo==undefined||resultDataInfo==null)
    	return;
	let personList = resultDataInfo.data;
	let listr = "";
	for (let i = 0; i < personList.length; i++) {
		let colorIndexRand = getrand(1, colorArr.length - 1);
		let colorStr = colorArr[colorIndexRand];
		listr += "<li onclick='openMap()' style='color: " + colorStr + "; padding:2px 2px;'>"  + personList[i].mineName +"&nbsp;"+ "</li>";
	}
	$("#mine_person").append(listr);
	return;
}
function openMap() {
	window.open("http://led.longder.com/mine_cuncaota_map/");
}
//设置矿明名叫啥
function setMineName() {
	let postData = {"appkey": "mine_group_name"};
	let settingsInfo = sensorServer.getSettingsByAppKey(postData);
	if (settingsInfo != undefined && settingsInfo != null) {
		if (settingsInfo.appval != undefined && settingsInfo.appval != null) {
			if (settingsInfo.appval == "")
				return;
			$("#mine_name").html(settingsInfo.appval);
		}
	}
}

//设置右上角时间
function setDateInfo() {
	let showDate = "2021-10-14  星期四  10:17:18";
	var nowDate = new Date();
	var year = nowDate.getFullYear();
	var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1)
		: nowDate.getMonth() + 1;
	var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate
		.getDate();
	var dateStr = year + "-" + month + "-" + day;

	var hour = nowDate.getHours();//获取系统时间
	var minute = nowDate.getMinutes(); //分
	var second = nowDate.getSeconds();//秒
	let hms = hour + ":" + minute + ":" + second;
	showDate = dateStr + " " + getWeekDate() + " " + hms;
	$("#current_date").html(showDate);
}

function getWeekDate() {
	var now = new Date();
	var day = now.getDay();
	var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
	var week = weeks[day];
	return week;
}

function quitSystem(){
	// let postData = {"appkey": "system_install_time"};
	// let settingsInfo = sensorServer.getSettingsByAppKey(postData);
	// if (settingsInfo != undefined && settingsInfo != null) {
	// 	if (settingsInfo.appval != undefined && settingsInfo.appval != null) {
	// 		console.log(settingsInfo.appval);
	// 		if (settingsInfo.appval == "")
	// 			return;
	//
	// 	}
	// }
	var userAgent = navigator.userAgent;
	if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") !=-1) {
		window.location.href="about:blank";
		window.close();
	} else {
		window.opener = null;
		window.open("", "_self");
		window.close();
	}
}

//===========================气体占比=====================================
//设置气体分布比重
let showPieDataIndex = 0;
let showPieDeviceId = "";
let showPieDeviceLocation = '';
var showOrderIndex = 0; //从第一个开始轮询一圈后，从头开始
function setChartPieNew() {
	let resultData = sensorServer.getSensorList({"page": 1, "rows": 1000});
	if(resultData==undefined||resultData==null)
		return;
	let sensorList = resultData.data;
	refShowPieData(); //进来了先执行一次。
	setInterval(refShowPieData, 5000);

	function refShowPieData() {
		showPieDataIndex++;
		if (showOrderIndex == sensorList.length - 1)
			showOrderIndex = 0;
		if (showPieDataIndex == sensorList.length - 1)
			showPieDataIndex = 0;

		let chartInfo;
		var data = genData(sensorList[showPieDataIndex]);
		if(data==undefined)
			return;
		showPieDeviceId = sensorList[showPieDataIndex].deviceid;
		showPieDeviceLocation = sensorList[showPieDataIndex].devicelocation;
		console.log("当前正在循环的设备：" + showPieDeviceId);
		let chartDom = document.getElementById('containerPie');
		chartInfo = echarts.init(chartDom); //
		let option;
		option = {
			title: {
				text: sensorList[showPieDataIndex].devicelocation, //气体统计
				subtext: '',// '监测点：'+sensorList[showPieDataIndex].devicelocation,
				left: 'left',
				textStyle: {color: 'rgba(229,242,57,0.49)', fontSize: 14}
				//align: 'left',
			},
			tooltip: {
				trigger: 'item',
				formatter: '{a} <br/>{b} : {c} ({d}%)'
			},
			color: [
				"#f24633",
				"#fff43f",
				"#1caa17"],
			legend: {
				type: 'scroll',
				// orient: 'vertical',
				// right: 10,
				top: "bottom",
				// bottom: 20,
				data: data.legendData,
				selected: data.selected,
				textStyle: {
					color: "#fff"
				}
			},
			series: [
				{
					name: '检测值',
					type: 'pie',
					radius: '55%',
					// center: ['40%', '50%'],
					data: data.seriesData,
					emphasis: {
						itemStyle: {
							shadowBlur: 10,
							shadowOffsetX: 0,
							shadowColor: 'rgba(248,255,52,0.5)'
						}
					},
					itemStyle: {
						normal: {
							label: {
								show: true,
								formatter: '{b} : {c} ({d}%)'
							},
							labelLine: {show: true}
						}
					}
				}
			]
		};
		chartInfo.clear();
		option && chartInfo.setOption(option);
	}

	function genData(sensorInfo) {
		if (sensorInfo == undefined || sensorInfo == null)
			return;
		var nameList = [
			'CH4', 'CO2', 'O2', 'N2'];
		var seriesData = [];
		var selected = {};
		for (var i = 0; i < nameList.length; i++) {
			name = nameList[i];
			// 	seriesData.push({
			// 		name: name,
			// 		value: 0.01
			// 	});
			selected[name] = i < nameList.length;
		}
		seriesData.push({name: "CH4", value: sensorInfo.ch4});
		seriesData.push({name: "CO2", value: sensorInfo.co2});
		//seriesData.push("CO",sensorInfo.co);
		seriesData.push({name: "O2", value: sensorInfo.o2});
		let n2 = (100 - sensorInfo.ch4 - sensorInfo.co2 - sensorInfo.co - sensorInfo.o2).toFixed(2);
		seriesData.push({name: "N2", value: n2});
		return {
			legendData: nameList,
			seriesData: seriesData,
			selected: selected
		};
	}
}

//===========================气体趋势=====================================
//显示顺序
var showOrderText = ['ch4', 'co2', 'co', 't', 'o2']

//var showOrderIndex=0; //从第一个开始轮询一圈后，从头开始
function set_chart_sensorDataByDay() {
	let option;
	//let obj = JSON.parse("./dark.json");
	// echarts.registerTheme('dark', obj);
	let chartDom = document.getElementById('chart_sensorDataByDay');
	let myChart = echarts.init(chartDom); //,'dark','dark'

	let startDay = '';//getTodayPrev();
	let endDay = getToday();
	startDay = getPreMonth(endDay);
	let deviceId = showPieDeviceId;//'';
     debugger;
	let resultData = sensorServer.getSensorDataListByDay({
		"page": 1,
		"rows": 30,
		"deviceId": deviceId,
		"startDay": startDay,
		"endDay": endDay
	});
	if(resultData==undefined||resultData==null)
		return;
	let resutDataList = resultData.data;
	let devicelocationText = showPieDeviceLocation;
	lunxun();//先执行一次
	setInterval(lunxun, 3000);

	let itemStyle_1 = {
		normal: {
			color: '#f8ff34',
			lineStyle: {
				color: '#fff43f'
			}
		}
	};
	let itemStyle_2 = {
		normal: {
			color: '#f24633',
			lineStyle: {
				color: '#ff2a2c'
			}
		}
	};

	let lunxun3Index = 0;
	var lunxun3Interval;

	function lunxun() {
		showPieDataIndex++;
		let resultData = sensorServer.getSensorList({"page": 1, "rows": 1000});
		if(resultData==undefined||resultData==null)
			return;
		let sensorList = resultData.data;
		if(resultData.total==1||showPieDataIndex==resultData.total-1)
			showPieDataIndex=0;
		showPieDeviceId = sensorList[showPieDataIndex].deviceid;
		showPieDeviceLocation = sensorList[showPieDataIndex].devicelocation;
		console.log("当前正在循环的设备：" + showPieDeviceId);

		devicelocationText = showPieDeviceLocation;
		$("#show30Day").html(devicelocationText);
		deviceId = showPieDeviceId;
		resultData = sensorServer.getSensorDataListByDay({
			"page": 1,
			"rows": 30,
			"deviceId": deviceId,
			"startDay": startDay,
			"endDay": endDay
		});
		resutDataList = resultData.data;
		console.log("lunx----2222  " + new Date());
		setTimeout(lunxun1, 3000)
	}

	function lunxun1() {
		console.log("lunx----3333  " + new Date());
		let dimensionsArr = [];
		//debugger;
		for (let i = 0; i < resutDataList.length; i++) {
			dimensionsArr.push(resutDataList[i].day);
		}
		let sourceArr = [];
		let seriesTypeArr = [];
		let dimensionsTypeArr = [];
		//----------------------------轮询 不同气体----------------------------
		//debugger;
		let colorArr = ["#ea0275", "#3c8cd2", "#eaea22", , "rgba(229,242,57,0.58)",]
		if (lunxun3Index == 0) {
			dimensionsTypeArr = ['product', 'CH4', 'CO2'];
			sourceArr = [];
			console.log(dimensionsTypeArr.length);
			for (let i = 0; i < dimensionsArr.length; i++) {
				let parms = {'product': dimensionsArr[i]};
				if (resutDataList[i] != undefined && resutDataList[i] != null) {
					createJson(parms, 'CH4', resutDataList[i].maxCh4);
					createJson(parms, 'CO2', resutDataList[i].maxCo2);
					sourceArr.push(parms);
				}
			}
			for (let i = 0; i < dimensionsTypeArr.length - 1; i++) {
				var infoChild = new dimensionsTypeInfo();
				infoChild.type = 'line';
				infoChild.smooth = true;
				if (i == 0) {
					infoChild.itemStyle = itemStyle_1;
				} else {
					infoChild.itemStyle = itemStyle_2;
				}
				seriesTypeArr.push(infoChild);
			}
		} else {
			dimensionsTypeArr = ['product', 'CO', 'T', 'O2', 'RH'];
			sourceArr = [];
			console.log(dimensionsTypeArr.length);
			for (let i = 0; i < dimensionsArr.length; i++) {
				let parms = {'product': dimensionsArr[i]};
				if (resutDataList[i] != undefined && resutDataList[i] != null) {
					createJson(parms, 'CO', resutDataList[i].maxCo);
					createJson(parms, 'T', resutDataList[i].maxTemperature);
					createJson(parms, 'O2', resutDataList[i].minO2);
					createJson(parms, 'RH', resutDataList[i].maxHumidity);
					sourceArr.push(parms);
				}
			}

			for (let i = 0; i < dimensionsTypeArr.length - 1; i++) {
				var infoChild = new dimensionsTypeInfo();
				if (i > 1) {
					infoChild.type = 'line'; //bar
				} else {
					infoChild.type = 'bar';
				}
				infoChild.smooth = true;
				seriesTypeArr.push(infoChild);
			}
		}

		//debugger
		let msgInfo = "title: " + (dimensionsTypeArr.length - 1).toString() + " data: " + (sourceArr.length - 1).toString();
		console.log(msgInfo);
		option = {
			color: colorArr,
			title: {
				text: '', devicelocationText,
				textStyle:
					{
						//标题
						color: 'rgba(255,54,44,0.49)', fontSize: 14, align: 'center'
					}
			},
			left: 'left',
			textAlign: 'left',
			legend: {
				textStyle: {
					color: 'rgba(229,242,57,0.64)'
				}
			},
			tooltip: {},
			dataset: {

				dimensions: dimensionsTypeArr, //['product', 'ch4', 'co2'],//,'co'
				source: sourceArr /*[
						{product: 'Matcha Latte', '2015': 43.3, '2016': 85.8, '2017': 93.7,'2018':20.8},
						{product: 'Milk Tea', '2015': 83.1, '2016': 73.4, '2017': 55.1,'2018':20.8},
						{product: 'Cheese Cocoa', '2015': 86.4, '2016': 65.2, '2017': 82.5,'2018':20.8},
						{product: 'Walnut Brownie', '2015': 72.4, '2016': 53.9, '2017': 39.1,'2018':20.8}
					]*/

			},
			xAxis: {
				type: 'category',
				axisLine: {
					lineStyle: {
						color: "rgb(232,255,243)"
					}
				}
			},
			yAxis: {
				type: 'value',
				axisLine: {
					lineStyle: { //Y轴线
						color: "rgb(197,237,242)"
					}
				},
				splitLine: {
					lineStyle: {
						// 使用深浅的间隔色 (格子的样色线条)
						color: ['#dda', '#ddd']
					}
				}

				//,
				// axisTick:{
				// 	lineStyle: { //Y轴线 刻度线
				// 		color: "rgb(242,70,51)"
				// 	}
				// }
			},

			// Declare several bar series, each will be mapped
			// to a column of dataset.source by default.
			series: seriesTypeArr
			/*[
			  //{type: 'bar'},
			  //{type: 'bar'}
			  // {type: 'bar'},
			  // {type: 'bar'}
		  //] */
		};
		myChart.clear(); //在setOption之前加上该语句即可
		option && myChart.setOption(option);
		window.onresize=function(){
			myChart.resize();
		}
		if (lunxun3Index > 0) {
			clearInterval(lunxun3Interval);
			lunxun3Index = 0;
			return;
		}
		lunxun3Index = lunxun3Index + 1;
	}

	//每隔3秒换一个数据显示
	function lunxun2() {
		let gasType = showOrderText[showOrderIndex];
		console.log(new Date());
		showOrderIndex++;
		if (showOrderIndex == showOrderText.length - 1)
			showOrderIndex = 0;
		let xListData = [];
		for (let i = 0; i < resutDataList.length; i++) {
			xListData.push(resutDataList[i].day.replace("-", "."));
		}
		let yListData = [];
		for (let i = 0; i < resutDataList.length; i++) {
			//yListData.push(resutDataList[i].maxTemperature);
			if (gasType.toUpperCase() == 'CH4')
				yListData.push(resutDataList[i].maxCh4);
			if (gasType.toUpperCase() == 'CO2')
				yListData.push(resutDataList[i].maxCo2);
			if (gasType.toUpperCase() == 'CO')
				yListData.push(resutDataList[i].maxCo);
			if (gasType.toUpperCase() == 'T')
				yListData.push(resutDataList[i].maxTemperature);
			if (gasType.toUpperCase() == 'O2')
				yListData.push(resutDataList[i].minO2);
		}

		let seriesType = 'bar';
		// if(showOrderIndex%2){
		// 	seriesType='line';
		// }
		let option = {
			title: {
				text: "  检测数据:" + gasType,
				textStyle: {color: 'rgba(92,29,164,0.49)', fontSize: 14, align: 'center'}
			},
			xAxis: {
				type: 'category',
				data: xListData //['CH4', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
			},
			yAxis: {
				type: 'value'
			},
			series: [
				{
					data: yListData,//[820, 932, 901, 934, 1290, 1330, 1320],
					type: seriesType,// 'bar',
					smooth: true
				}
			]
		};
		option && myChart.setOption(option);
	}

}

function getToday() {
	//现在
	var time = new Date();
	var day = ('0' + time.getDate()).slice(-2);
	var month = ('0' + (time.getMonth() + 1)).slice(-2);
	var today = time.getFullYear() + '-' + month + '-' + day;
	//$('#startDate2').val(today);
	return today;
}

function getPreMonth(date) {
	var arr = date.split('-');
	var year = arr[0]; //获取当前日期的年份
	var month = arr[1]; //获取当前日期的月份
	var day = arr[2]; //获取当前日期的日
	var days = new Date(year, month, 0);
	days = days.getDate(); //获取当前日期中月的天数
	var year2 = year;
	var month2 = parseInt(month) - 1;
	if (month2 == 0) {
		year2 = parseInt(year2) - 1;
		month2 = 12;
	}
	var day2 = day;
	var days2 = new Date(year2, month2, 0);
	days2 = days2.getDate();
	if (day2 > days2) {
		day2 = days2;
	}
	if (month2 < 10) {
		month2 = '0' + month2;
	}
	var t2 = year2 + '-' + month2 + '-' + day2;
	return t2;
}

// 参数：json = json对象 ，prop = 属性，val = 值
function createJson(json, prop, val) {
	// 如果 val 被忽略
	if (typeof val === "undefined") {
		// 删除属性
		delete json[prop];
	} else {
		// 添加 或 修改
		json[prop] = val;
	}
}

function dimensionsTypeInfo(type, smooth, itemStyle) {
	this.type = type;
	this.smooth = smooth;
	this.itemSize = itemStyle;
}

//date1：开始日期，date2结束日期 //获得天数
function GetNumberOfDays(date1, date2) {
	var a1 = Date.parse(new Date(date1));
	var a2 = Date.parse(new Date(date2));
	var day = parseInt((a2 - a1) / (1000 * 60 * 60 * 24));//核心：时间戳相减，然后除以天数
	return day
}


function fullScreen(el) {
	var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen,
		wscript;

	if (typeof rfs != "undefined" && rfs) {
		rfs.call(el);
		return;
	}

	if (typeof window.ActiveXObject != "undefined") {
		wscript = new ActiveXObject("WScript.Shell");
		if (wscript) {
			wscript.SendKeys("{F11}");
		}
	}
}

function exitFullScreen(el) {
	var el = document,
		cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen || el.exitFullScreen,
		wscript;

	if (typeof cfs != "undefined" && cfs) {
		cfs.call(el);
		return;
	}

	if (typeof window.ActiveXObject != "undefined") {
		wscript = new ActiveXObject("WScript.Shell");
		if (wscript != null) {
			wscript.SendKeys("{F11}");
		}
	}
}

function getrand(m, n) {
	var rand = Math.floor(Math.random() * (n - m + 1)) + m;//#核心代码
	return rand;
}
/***************************************
 * 生成从minNum到maxNum的随机数。
 * 如果指定decimalNum个数，则生成指定小数位数的随机数
 * 如果不指定任何参数，则生成0-1之间的随机数。
 *
 * @minNum：[数据类型是Integer]生成的随机数的最小值（minNum和maxNum可以调换位置）
 * @maxNum：[数据类型是Integer]生成的随机数的最大值
 * @decimalNum：[数据类型是Integer]如果生成的是带有小数的随机数，则指定随机数的小数点后的位数
 *
 ****************************************/
function randomNum(maxNum, minNum, decimalNum) {
	var max = 0, min = 0;
	minNum <= maxNum ? (min = minNum, max = maxNum) : (min = maxNum, max = minNum);
	switch (arguments.length) {
		case 1:
			return Math.floor(Math.random() * (max + 1));
			break;
		case 2:
			return Math.floor(Math.random() * (max - min + 1) + min);
			break;
		case 3:
			return (Math.random() * (max - min) + min).toFixed(decimalNum);
			break;
		default:
			return Math.random();
			break;
	}
}

